package com.zhongfl.crm.api.view;

import com.github.pagehelper.PageInfo;
import com.zhongfl.crm.model.LxUser;
import com.zhongfl.crm.request.LxUserRequest;
import com.zhongfl.crm.service.LxUserService;
import org.springframework.web.bind.annotation.*;
import tech.heptagram.core.common.rest.ResponseResult;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 向日葵
 * @Date 2018/9/20
 */
@RestController
@RequestMapping("/api/user")
public class LxUserApiController {

    @Resource
    private LxUserService lxUserService;

    @PostMapping("/list")
    public ResponseResult<PageInfo<LxUser>> findUserList(@RequestBody LxUserRequest lxUserRequest) {
        List<LxUser> list = lxUserService.findUserList(lxUserRequest);
        PageInfo<LxUser> users = new PageInfo<>(list);
        return new ResponseResult<>(users);
    }

    @PostMapping("/staffList/{departmentId}")
    public ResponseResult<PageInfo<LxUser>> findByLxId(@PathVariable Long departmentId) {
        List<LxUser> list = lxUserService.findByDepartmentId(departmentId);
        PageInfo<LxUser> users = new PageInfo<>(list);
        return new ResponseResult<>(users);
    }

    @GetMapping("/queryAll")
    public ResponseResult<List<LxUser>> findAllUser(){
        List<LxUser> users = lxUserService.findAllUser();
        return new ResponseResult<>(users);
    }

}
